package com.example.administrator.xxnapp;

import android.content.Context;
import android.widget.Toast;

import com.example.administrator.xxnapp.bean.VersionBean;
import com.example.administrator.xxnapp.http.CustomStringCallback;
import com.example.administrator.xxnapp.http.HttpUrl;
import com.example.administrator.xxnapp.login.IViewVersion;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.OkGo;

import java.lang.reflect.Type;

import cn.mdruby.baselibrary.utils.ABAppUtil;

/**
 * Created by Administrator on 2018/5/16.
 */

public class AppPresenter {
    private IViewApp mIView;
    private IModelApp mIModel;

    public AppPresenter(IViewApp mIView, IModelApp mIModel) {
        this.mIView = mIView;
        this.mIModel = mIModel;
    }

    public AppPresenter(IViewApp mIView) {
        this.mIView = mIView;
    }

    public void getVersion(final Context context){
        mIModel.getVersion().execute(new CustomStringCallback() {
            @Override
            public void onSuccessString(Gson gson, String responseBody) {
                Type type = new TypeToken<VersionBean>() {
                }.getType();
                VersionBean bean = gson.fromJson(responseBody,type);
                if (bean!= null){
                    int appVersion = ABAppUtil.getAppVersionCode(context);
                    if (bean.getVersionCode()>appVersion){
                        mIView.onGetVersionSuccess(bean);
//                        path = bean.getPath();
                    }
                }
            }
        });
    }
}
